<?php
require(__META_CONTROLS_GEN__ . '/ComNoteMetaControlGen.class.php');

/**
 * This is a MetaControl customizable subclass, providing a QForm or QPanel access to event handlers
 * and QControls to perform the Create, Edit, and Delete functionality of the
 * ComNote class.  This code-generated class extends from
 * the generated MetaControl class, which contains all the basic elements to help a QPanel or QForm
 * display an HTML form that can manipulate a single ComNote object.
 *
 * To take advantage of some (or all) of these control objects, you
 * must create a new QForm or QPanel which instantiates a ComNoteMetaControl
 * class.
 *
 * This file is intended to be modified.  Subsequent code regenerations will NOT modify
 * or overwrite this file.
 *
 * @package My QCubed Application
 * @subpackage MetaControls
 */
class ComNoteMetaControl extends ComNoteMetaControlGen {
    // Initialize fields with default values from database definition
    /*
		public function __construct($objParentObject, ComNote $objComNote) {
			parent::__construct($objParentObject,$objComNote);
			if ( !$this->blnEditMode ){
				$this->objComNote->Initialize();
			}
		}
    */              protected $dttTime;

    public function calDate_Create($strControlId = null) {
        $this->calDate = new QCalendarPopup($this->objParentObject, $strControlId);
        $this->calDate->Name = QApplication::Translate('Date');
        //$this->calDate->DateTimePickerType = QDateTimePickerType::Date;
        if ($this->blnEditMode)
            $this->calDate->DateTime = $this->objComNote->Date;
        else { //new
            $DefualtDate = new QDateTime();
            $DefualtDate->SetDate(date("Y"), date("m"), date("d"));
            $this->calDate->DateTime= $DefualtDate;
        }
        return $this->calDate;
    }

    public function SaveComNote() {
        try {
            //Prepare data for Record Info
            $this->dttTime = new QDateTime();
            $this->dttTime->setDate (date("Y"), date("m"), date("d"));
            $this->dttTime->setTime (date("H"), date("i"), date("s"));
            //Get Current user
            $CurrentUser = $_SESSION['User']['Id'];
            //Should eUser
            $eUser = $_SESSION['User']['Id'];

            $this->objComNote->Euser = $eUser;
            // Update any fields for controls that have been created
            $this->objComNote->SchoolComId =  $_SESSION['ComSchoolId'];
            if ($this->lstTypeObject) $this->objComNote->Type = $this->lstTypeObject->SelectedValue;
            if ($this->calDate)  $this->objComNote->Date = $this->calDate->DateTime;
            //if ($this->txtAttachments) $this->objComNote->Attachments = $this->txtAttachments->Text;
            if ($this->txtNotes) $this->objComNote->Notes = $this->txtNotes->Text;

            if ($this->blnEditMode) {
                //*** Update
                $this->objComNote->UpdateBy   = $CurrentUser;
                $this->objComNote->UpdateDate = $this->dttTime;
            }
            else {
                //**** New
                $this->objComNote->CreateBy   = $CurrentUser;
                $this->objComNote->CreateDate = $this->dttTime;
            }
            $this->objComNote->Save();


            // Finally, update any ManyToManyReferences (if any)
        } catch (QCallerException $objExc) {
            $objExc->IncrementOffset();
            throw $objExc;
        }
    }
}
?>